package com.aij.starter.event;

import java.util.Vector;
import java.util.concurrent.locks.ReentrantLock;

import com.aij.starter.jna.ChatGlm.ChatGlmLibrary;

/**
 * ChatGlm回调处理
 * @author aij
 */
public class ChatGlmEventHandler implements ChatGlmLibrary.OnNewWord {

    public static ReentrantLock mutex = new ReentrantLock();
    public static Vector<String> txtList = new Vector<String>();

	@Override
	public void callback(String text) {
        mutex.lock();
        txtList.add(text);
        mutex.unlock();
	}

    public static boolean TextFinished()
    {
    	boolean ret = false;
        mutex.lock();
        if (txtList.size() > 0)
        {
            ret = true;
        }
        mutex.unlock();
        return ret;
    }

    public static String PopText()
    {
        String ret = null;
        mutex.lock();
        if (txtList.size() > 0)
        {
            ret = txtList.get(0);
            txtList.remove(0);
        }
        mutex.unlock();
        return ret;
    }
	
}
